<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-shopping-bag-2"></i> 认证企业 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-date-picker class="mr10" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
                        v-model="query.time">
        </el-date-picker>
        <el-select class="mr10" v-model="query.sel" placeholder="请选择状态">
          <el-option label="全部状态" value=""></el-option>
          <el-option label="待审核" value="1"></el-option>
          <el-option label="审核通过" value="2"></el-option>
          <el-option label="审核不通过" value="3"></el-option>
        </el-select>
        <el-input placeholder="请输入公司名称查询" v-model="query.souVal" class="handle-input mr10"></el-input>

        <el-button type="primary" icon="el-icon-search" @click="souClick">搜索</el-button>
      </div>
      <el-table v-loading="loading" :data="tableData" border class="table" style="width: 100%" ref="multipleTable"
                header-cell-class-name="table-header" @selection-change="SelectionChange">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="公司logo" width="100">
          <template slot-scope="scope">
            <el-image style="width: 80px; height: 80px" :src="scope.row.aLogo" fit="fill" :preview-src-list="[scope.row.aLogo]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="aCompanyName" label="公司名称" width="210">
          <template slot-scope="scope">
            <el-link :underline="false" type="primary" @click="deDataClick(scope.row)">{{scope.row.aCompanyName}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="lpName" label="法人姓名" width="100"></el-table-column>
        <el-table-column prop="lpPhone" label="法人电话" width="150"></el-table-column>
        <el-table-column prop="directorName" label="负责人姓名" width="100"></el-table-column>
        <el-table-column prop="directorPhone" label="负责人电话" width="150"></el-table-column>
        <el-table-column prop="authTime" label="创建时间" width="210"></el-table-column>
        <el-table-column fixed="right" prop="mobileCreate" label="状态" width="120" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.aStatus == 1">待审核</el-tag>
            <el-tag v-if="scope.row.aStatus == 2" type="success">审核通过</el-tag>
            <el-tag v-if="scope.row.aStatus == 3" type="danger">审核不通过</el-tag>
            <el-tooltip v-if="scope.row.aStatus == 3" :content="scope.row.failReason" placement="top">
              <i class="el-icon-warning"></i>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="210" align="center">
          <template slot-scope="scope">
            <el-button v-if="scope.row.aStatus == 1" type="text" icon="el-icon-check" class="red" @click="exYesClick(scope.row.aId)"
                       :loading="exYesLoad">审核通过</el-button>
            <el-button v-if="scope.row.aStatus == 1" type="text" icon="el-icon-close" class="red" @click="exNoClick(scope.row.aId)">审核不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.page" :page-size="query.limit" :total="page.totalCount"
                       :pager-count="5" @current-change="PageChange" @prev-click="PageChange" @next-click="PageChange"></el-pagination>
      </div>
      <!-- 详细信息 -->
      <el-drawer title="详细信息" :visible.sync="deDataFlg" size="70%" :with-header="false">
        <div class="nameDrawer">
          <el-divider content-position="left">基本信息</el-divider>
          <el-row :gutter="10">
            <el-col :span="12">
              <p>公司名称</p>
              <p>{{itemObj.aCompanyName}}</p>
            </el-col>
            <el-col :span="12">
              <p>公司座机</p>
              <p>{{itemObj.aLandline}}</p>
            </el-col>
            <el-col :span="24">
              <p>公司地址</p>
              <p>{{itemObj.aCompanyAddress}}</p>
            </el-col>
            <el-col :span="12">
              <p>公司logo</p>
              <p>
                <el-image style="width: 100px;" :src="itemObj.aLogo" fit="fill" :preview-src-list="[itemObj.aLogo]"></el-image>
              </p>
            </el-col>
            <el-col :span="12">
              <p>公司营业执照</p>
              <p>
                <el-image style="width: 100px;" :src="itemObj.aBusinessLicence" fit="fill" :preview-src-list="[itemObj.aBusinessLicence]"></el-image>
              </p>
            </el-col>
          </el-row>
          <el-divider content-position="left">联系人信息</el-divider>
          <el-row :gutter="10">
            <el-col :span="8">
              <p>法人姓名</p>
              <p>{{itemObj.lpName}}</p>
            </el-col>
            <el-col :span="8">
              <p>法人身份证号</p>
              <p>{{itemObj.ipIdcard}}</p>
            </el-col>
            <el-col :span="8">
              <p>法人电话</p>
              <p>{{itemObj.lpPhone}}</p>
            </el-col>
            <el-col :span="8">
              <p>法人身份证正面</p>
              <p>
                <el-image style="width: 100px;" :src="itemObj.lpIdcardPositive" fit="fill" :preview-src-list="[itemObj.lpIdcardPositive]"></el-image>
              </p>
            </el-col>
            <el-col :span="16">
              <p>法人身份证反面</p>
              <p>
                <el-image style="width: 100px;" :src="itemObj.lpIdcardBack" fit="fill" :preview-src-list="[itemObj.lpIdcardBack]"></el-image>
              </p>
            </el-col>
            <el-col :span="8">
              <p>负责人姓名</p>
              <p>{{itemObj.directorName}}</p>
            </el-col>
            <el-col :span="8">
              <p>负责人身份证号</p>
              <p>{{itemObj.directorIdcard}}</p>
            </el-col>
            <el-col :span="8">
              <p>负责人电话</p>
              <p>{{itemObj.directorPhone}}</p>
            </el-col>
            <el-col :span="8">
              <p>负责人身份证正面</p>
              <p>
                <el-image style="width: 100px;" :src="itemObj.directorIdcardPositive" fit="fill" :preview-src-list="[itemObj.directorIdcardPositive]">
                </el-image>
              </p>
            </el-col>
            <el-col :span="16">
              <p>负责人身份证反面</p>
              <p>
                <el-image style="width: 100px;" :src="itemObj.directorIdcardBack" fit="fill" :preview-src-list="[itemObj.directorIdcardBack]">
                </el-image>
              </p>
            </el-col>
          </el-row>
          <el-row v-if="itemObj.aStatus == 1">
            <el-col :span="24">
              <!-- itemObj.aId -->
              <el-button type="primary" icon="el-icon-check" @click="exYesClick(itemObj.aId)" :loading="exYesLoad">审核通过</el-button>
              <el-button type="danger" icon="el-icon-close" @click="exNoClick(itemObj.aId)">审核不通过</el-button>
            </el-col>
          </el-row>
        </div>
      </el-drawer>
      <!-- 审核不通过 -->
      <el-dialog title="审核不通过" :visible.sync="exNoFlg" width="40%">
        <el-input type="textarea" :rows="5" placeholder="请输入审核不通过理由" v-model="exNoText">
        </el-input>
        <span slot="footer" class="dialog-footer">
          <el-button @click="exNoFlg = false">取 消</el-button>
          <el-button type="primary" @click="exNoTextBtnClick" :loading="exNoSubLoad">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { jdEnterpriseListInit, jdEnterpriseListStatus } from '../../../api/index';

export default {
  data() {
    return {
      loading: false,
      query: {
        page: 1,
        limit: 10,
        time: [],
        sel: '',
        souVal: ''
      },
      tableData: [],
      page: {
        totalCount: 100
      },

      //详细信息
      deDataFlg: false,
      itemObj: {},
      //审核成功
      exYesLoad: false,
      //审核不通过
      exNoFlg: false,
      exNoId: '',
      exNoSubLoad: false,
      exNoText: '',
    };
  },
  created() {
    this.getListData();
  },
  methods: {
    //列表信息
    getListData() {
      this.loading = true;
      let query = {
        startTime: this.query.time ? this.query.time[0] : '',
        endTime: this.query.time ? this.query.time[1] : '',
        kw: this.query.souVal,
        limit: this.query.limit,
        page: this.query.page,
        status: this.query.sel,
      };
      jdEnterpriseListInit(query).then((res) => {
        this.loading = false;
        if (res.code === 0) {
          this.tableData = res.recordList;
          this.page.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      });
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //翻页
    PageChange(num) {
      this.query.page = num;
      this.getListData();
    },
    //搜索
    souClick() {
      this.query.page = 1;
      this.getListData();
    },
    //选中
    SelectionChange() { },
    //查看详细信息
    deDataClick(item) {
      this.itemObj = item;
      this.deDataFlg = true;
    },
    //审核通过
    exYesClick(id) {
      this.exYesLoad = true;
      jdEnterpriseListStatus({
        authId: id,
        status: 2,
        failReason: '',
      }).then(res => {
        this.exYesLoad = false;
        if (res.code == 0) {
          this.$message.success("操作成功");
          this.deDataFlg = false;
          this.getListData();
        } else {
          this.$message(res.msg);
        }
      })
    },
    //审核不通过
    exNoClick(id) {
      this.exNoFlg = true;
      this.exNoId = id;
    },
    //提交审核不通过原因
    exNoTextBtnClick() {
      if (!this.exNoText) return false;
      this.exNoSubLoad = true;
      jdEnterpriseListStatus({
        authId: this.exNoId,
        status: 3,
        failReason: this.exNoText,
      }).then(res => {
        this.exNoSubLoad = false;
        if (res.code == 0) {
          this.$message.success("操作成功");
          this.deDataFlg = false;
          this.exNoFlg = false;
          this.getListData();
        } else {
          this.$message(res.msg);
        }
      })
    },
  }
};
</script>

<style scoped>
/deep/ :focus {
    outline: 0;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.nameDrawer {
    padding: 30px;
}
.nameDrawer .el-col p:nth-child(1) {
    font-size: 14px;
    color: #999;
    line-height: 30px;
}
.nameDrawer .el-col p:nth-child(2) {
    font-size: 14px;
    margin-bottom: 10px;
}
.nameDrawer .el-col .el-image {
    margin: 0 10px 10px 0;
}
.elSelect {
    width: 100%;
}
.upload-demo {
    height: 32px;
}
.heng-border {
    height: 0.5px;
    margin-bottom: 30px;
}
</style>
